//
//  LCYaoQingHtmlVC+YQShare.m
//  JKFuYinProject
//
//  Created by admin on 2018/3/27.
//  Copyright © 2018年 LC. All rights reserved.
//

#import "LCViewController+YQShare.h"
#import "UIViewController+LCMobShare.h"
#import <ShareSDKUI/ShareSDK+SSUI.h>
#import <ShareSDK/ShareSDK.h>

@implementation LCViewController (YQShare)

//#pragma mark - 分享
- (void)ZKKShareViewDidSelecteBtnWithBtnText:(NSString *)btText{
//    NSLog(@"---btText-%@",btText);

        NSString *url = [NSString stringWithFormat:@"%@/extension/create_img",http_toutiao];
        __weak typeof(self) weakSelf = self;
        [kNetworkTool POSTFuYinWithUrlString:url input:@{} success:^(NSDictionary * dict) {
            NetWorkModel *netWorkModel = [NetWorkModel yy_modelWithJSON:dict];
            NSDictionary *dic = netWorkModel.data;
            if (netWorkModel.status == 1) {
                    if ([btText isEqualToString:@"分享朋友圈"]) {
                        [weakSelf shareYaoQingMessageWithImageArray:@[dic[@"url"]] type:SSDKPlatformSubTypeWechatTimeline];
                    }
                    if ([btText isEqualToString:@"分享微信"]) {
                        [weakSelf shareYaoQingMessageWithImageArray:@[dic[@"url"]] type:SSDKPlatformSubTypeWechatSession];
                    }
                    if ([btText isEqualToString:@"分享QQ"]) {
                        [weakSelf shareYaoQingMessageWithImageArray:@[dic[@"url"]] type:SSDKPlatformSubTypeQQFriend];
                    }
                    if ([btText isEqualToString:@"QQ空间邀请"]) {
                        [weakSelf shareYaoQingMessageWithImageArray:@[dic[@"url"]] type:SSDKPlatformSubTypeQZone];
                    }
                    if ([btText isEqualToString:@"微博邀请"]) {
                        [weakSelf shareYaoQingMessageWithImageArray:@[dic[@"url"]] type:SSDKPlatformTypeSinaWeibo];
                    }
                    if ([btText isEqualToString:@"二维码邀请"]) {
                        [weakSelf shareYaoQingMessageWithImageArray:@[dic[@"url"]] type:(SSDKPlatformSubTypeWechatTimeline)];
                    }
                    if ([btText isEqualToString:@"更多邀请"]) {
                        UIImageView *imageView = [[UIImageView alloc] init];
                        [imageView sd_setImageWithURL:dic[@"url"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                            NSLog(@"imageURL = %@", imageURL);
                            [weakSelf openOSMoreWithText_image:imageView.image];
                        }];
                    }
            }else{
                [weakSelf setStringWarning:netWorkModel.msg];
            }
        } failure:^(NSError * error) {
            [weakSelf setStringWarning:NoNetwork];
        }];
    
}
- (void)shareYaoQingMessageWithImageArray:(NSArray *)imageArray type:(SSDKPlatformType)type{
    //1、创建分享参数
    if (imageArray) {
        
    }else{
        imageArray = @[[UIImage imageNamed:@"我的_设置_关于"]];
    }
    //
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    [shareParams SSDKSetupShareParamsByText:nil
                                     images:imageArray
                                        url:nil
                                      title:nil
                                       type:SSDKContentTypeImage];
    //进行分享
    [ShareSDK share:type //传入分享的平台类型
         parameters:shareParams
     onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
         
     }];
}

///MARK:- 系统更多分享
- (void)openOSMoreWithText_image:(UIImage *)text_image {
    NSArray *activityItemsArray;
    // 1、设置分享的内容，并将内容添加到数组中
    if (text_image) {
        UIImage *shareImage = text_image;
        activityItemsArray = @[shareImage];
    }
    
    // 2、初始化控制器，添加分享内容至控制器
    UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItemsArray applicationActivities:nil];
    //屏蔽掉系统的打印,拷贝,发给指定联系人,保存图片
    activityVC.excludedActivityTypes = @[UIActivityTypeMail,UIActivityTypePrint, UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll];
    activityVC.modalInPopover = YES;
    // 3、设置回调
    UIActivityViewControllerCompletionWithItemsHandler itemsBlock = ^(UIActivityType __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError){
        if (completed == YES) {
            NSLog(@"completed");
        }else{
            NSLog(@"cancel");
        }
    };
    activityVC.completionWithItemsHandler = itemsBlock;
    // 4、调用控制器
    [self presentViewController:activityVC animated:YES completion:nil];
}

@end
